package com.redbox.RedboxManagment.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import com.redbox.RedboxManagment.ejb.Order;

@Repository(value = "orderDao")
public class OrderImp extends HibernateDaoSupport implements IOrder {
	
	@Override
	@Transactional(readOnly = true)
	public Order findById(int pId) {
		String queryString= "from Card a where a.idCard=?";
		List<Order> result = getHibernateTemplate().find(queryString,pId);	
		
	    if (result.size() > 0) {
	        return result.get(0);
	    } else {
	        return null;
	    }   
	}

	@Override
	@Transactional
	public Order persistOnMerge(Order porder) {
		Order result = (Order) getHibernateTemplate().save(porder);
		return result;
	}

}